import {
  reqBaseCategoryList,
  reqGetBannerListData,
  reqGetFloorListData,
} from "@/api"

const state = {
  categoryList: [],
  bannerList: [],
  floorList: [],
}
const actions = {
  async getCategoryList({ commit }) {
    try {
      const result = await reqBaseCategoryList()
      commit("SAVE_CATEGORY_LIST", result.data)
    } catch (error) {
      console.log("请求失败！！！", error)
    }
  },
  async getBannerListData({ commit }) {
    const result = await reqGetBannerListData()
    if (result.code === 200) {
      commit("SAVE_BANNER_LIST_DATA", result.data)
    } else {
      console.log(123)
    }
  },
  async getFloorListData({ commit }) {
    const result = await reqGetFloorListData()
    if (result.code === 200) {
      commit("SAVE_FLOOR_LIST_DATA", result.data)
    }
  },
}
const mutations = {
  SAVE_CATEGORY_LIST(state, data) {
    state.categoryList = data
  },
  SAVE_BANNER_LIST_DATA(state, data) {
    state.bannerList = data
  },
  SAVE_FLOOR_LIST_DATA(state, data) {
    state.floorList = data
  },
}

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters: {},
}
